import router from '@/router'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { Session } from '@/utils/storage';

import { useAppStore } from '@/store/app'

NProgress.configure({
  showSpinner: false
}) // NProgress Configuration

router.beforeEach((to, from, next) => {
  NProgress.start()
  NProgress.inc() //随机增长进度条 但是进度条永远达不到100%

  if (!Session.get('token') && !to.meta.anonymous) {
    //  没有token 的用户应该做什么
    // window.location.href = process.env.VITE_APP_LOGIN_PATH + window.location.href
    console.log('permission触发')
    Session.clear()
    //TODO  暂时放这
    next()
    return false
  }
  next()
})

router.afterEach((to, from) => {
  NProgress.done() // finish progress bar
})
